package com.mt.roll.wms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.EquipmentBomParam;
import com.mt.roll.wms.params.EquipmentBomQueryParam;
import com.mt.roll.wms.service.EquipmentBomService;
import com.mt.roll.wms.vo.EquipmentBomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2021/1/4 10:06
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "equipment-bom")
@Slf4j
@Api(value = "设备物料BOM", tags = "设备物料BOM", hidden = false)
public class EquipmentBomController {
    @Autowired
    EquipmentBomService equipmentBomService;

    /**
     * 输入关键字后 点击查询按钮 查询
     * */
    @PostMapping(value = "findAllByEQNameOrEQCodeOrMaterialNameWithPage")
    @ApiOperation(value = "1.依据设备名、设备code来获取物料bom 列表(传入keywords) ;2.依据设备物料bomName 查询物料bom查询（传入materialName）")
    private R<IPage<EquipmentBomVo>> findAllByEQNameOrEQCodeOrMaterialNameWithPage(@Validated({Default.class}) @RequestBody EquipmentBomQueryParam equipmentBomBaseParam) {
        return equipmentBomService.findAllByEQNameOrEQCode(equipmentBomBaseParam);
    }

    @PostMapping(value = "findById")
    @ApiOperation(value = "依据物料bom id查询")
    private R<EquipmentBomVo> findById(@Validated({Default.class}) @RequestBody IdParam idParam) {
        return equipmentBomService.findById(idParam);
    }

    /**
     * 新建物料bom
     * */
    @PostMapping(value = "create")
    @ApiOperation(value = "新建物料bom")
    private R<Boolean> create(@Validated({Default.class}) @RequestBody EquipmentBomParam equipmentBomParam) {
        return equipmentBomService.create(equipmentBomParam);
    }

    /**
     * 更新物料bom
     * */
    @PostMapping(value = "update")
    @ApiOperation(value = "更新物料bom  依据ID 修改（传需要改的内容或者都传都行。）")
    private R<Boolean> update(@Validated({Default.class}) @RequestBody EquipmentBomParam equipmentBomParam) {
        return equipmentBomService.update(equipmentBomParam);
    }

    /**
     * 删除物料bom
     * */
    @PostMapping(value = "delete")
    @ApiOperation(value = "删除物料bom （依据ID 删除）")
    private R<Boolean> delete(@Validated @RequestBody IdParam idParam) {
        return equipmentBomService.delete(idParam);
    }

}
